Type GUI_v0_MainComponent_RuntimePopup Extends GUI_v0_MainComponent_Abstract

	Field alpha:Float
	Field alphaOld:Float
	Field show:Int
	Field img:TImage
	Field ups:RateCounter
	Field fps:RateCounter

	Method Initialize(main:GUI_v0_Main)
		ups      = New RateCounter
		fps      = New RateCounter
		alpha    = 0
		alphaOld = 0
		show     = False
		
		img = GFX_TextureRender.Create(256, 128)	
		GFX_TextureRender.BeginTexture(img)
			main.ResetGraphics()
			GFX_TextureRender.Cls()

			SetColor(0, 0, 255)
			SetAlpha(0.75)
			DrawRect(1, 1, 254, 126)

			SetColor(255, 255, 255)
			SetAlpha(1)
			DrawLine(0, 0, 255, 0, False)
			DrawLine(255, 0, 255, 127, False)
			DrawLine(255, 127, 0, 127, False)
			DrawLine(0, 127, 0, 0, False)
			
			DrawText(AppTitle, (256 - TextWidth(AppTitle)) / 2, 5)
			DrawText("Fps: ", 10, 25)
			DrawText("Ups: ", 10, 40)
			DrawText("Mem: ", 10, 55)
		GFX_TextureRender.EndTexture()
	End Method

	Method Update(main:GUI_v0_Main)
		ups.Count()
		Local pInput:GUI_PolledInput = GUI_PolledInput.GetInstance()
		If pInput.KeyDown(KEY_TAB) Then
			show = 1
		Else
			show = -1
		End If
		alphaOld = alpha
		alpha:+ (0.0005 * main.UPDATE_SCALE) * show
		If alpha < 0.0 Then
			alpha = 0.0
		Else If alpha > 1.0 Then
			alpha = 1.0
		End If
	End Method
	
	Method Render(main:GUI_v0_Main, tween:Float)
		fps.Count()
		Local a:Float = alpha * tween + alphaOld * (1.0 - tween)
		main.ResetGraphics()
		SetAlpha(a)
		Local x:Int = 10
		Local y:Int = 10
		DrawImage(img, x, y)
		DrawText(fps.GetRate(), x + 50, y + 25)
		DrawText(ups.GetRate(), x + 50, y + 40)
		DrawText((GCMemAlloced() / 1024) + "KB", x + 50, y + 55)
	End Method

	Method Uninitialize(main:GUI_v0_Main)
		alpha    = Null
		alphaOld = Null
		img = Null
		ups = Null
		fps = Null
		img = Null
	End Method
	
	Method GetUpdatePriority:Int()
		' We want to be processed first for update.
		Return 2147483647
	End Method

	Method GetRenderPriority:Int()
		' We want to be rendered last.
		Return 2147483647
	End Method


End Type
